/*
 * PayloadData.h
 *
 *  Created on: Jul 8, 2011
 *      Author: matthew
 */

#ifndef PAYLOADDATA_H_
#define PAYLOADDATA_H_

#include <vector>

using namespace std;

template<class T> class CPayloadData {
		vector<T> *pPayloadData;
		float fTimestamp;
	public:
		CPayloadData();
		CPayloadData(unsigned int);
		CPayloadData(vector<T>);
		CPayloadData(float, vector<T>);
		CPayloadData(CPayloadData const &);
		CPayloadData operator=(CPayloadData const &);
		~CPayloadData();
		void SetSize(unsigned int);
		void SetTimestamp(float);
		void SetValue(unsigned int, T);
		void AddData(T);
		T GetValue(unsigned int);
		float GetTimestamp();
		vector<T> GetData();
};

template<class T> CPayloadData<T>::CPayloadData(){
	pPayloadData = new vector<T>;
	pPayloadData->reserve(8); // Reserve space for 8 bytes of data
	fTimestamp = 0.0;
}

template<class T> CPayloadData<T>::CPayloadData(unsigned int nSize){
	pPayloadData = new vector<T> (nSize, 0);
	fTimestamp = 0.0;
}

template<class T> CPayloadData<T>::CPayloadData(vector<T> data){
	pPayloadData = new vector<T> (data);
	fTimestamp = 0.0;
}

template<class T> CPayloadData<T>::CPayloadData(float fTime, vector<T> data){
	pPayloadData = new vector<T> (data);
	fTimestamp = fTime;
}

template<class T> CPayloadData<T>::CPayloadData(CPayloadData const &rhs){
	pPayloadData = new vector<T> (*(rhs.pPayloadData));
	fTimestamp = rhs.fTimestamp;
}

template<class T> CPayloadData<T> CPayloadData<T>::operator=(CPayloadData<T> const &rhs){
	if (this != &rhs)
	{
		delete pPayloadData;
		pPayloadData = new vector<T> (*(rhs.pPayloadData));
		fTimestamp = rhs.fTimestamp;
	}
	return *this;
}

template<class T> CPayloadData<T>::~CPayloadData(){
	delete pPayloadData;
}

template<class T> void CPayloadData<T>::SetSize(unsigned int nSize){
	if (nSize >= 0)
		pPayloadData->resize(nSize, 0);
}

template<class T> void CPayloadData<T>::SetTimestamp(float fTime){
	fTimestamp = fTime;
}

template<class T> void CPayloadData<T>::SetValue(unsigned int nIndex, T nValue){
	if (nIndex < pPayloadData->size())
		pPayloadData->at(nIndex) = nValue;
}

template<class T> void CPayloadData<T>::AddData(T nData){
	pPayloadData->push_back(nData);
}

template<class T> T CPayloadData<T>::GetValue(unsigned int nIndex){
	if (nIndex < pPayloadData->size())
		return pPayloadData->at(nIndex);
	else
		return 0;
}

template<class T> float CPayloadData<T>::GetTimestamp(){
	return fTimestamp;
}

template<class T> vector<T> CPayloadData<T>::GetData(){
	return *pPayloadData;
}

#endif /* PAYLOADDATA_H_ */
